home *** CD-ROM | disk | FTP | other *** search
- #include "menusharing.h"
- #include "FinderMenuInterface.h"
- #include <iac.h>
- #include <Notification.h>
-
- static short flexitmainloop = false; /*when true we fall thru the main event loop*/
-
- static short theFirstMenuID;
-
- static AEDescList thePathList;
- static Boolean thePathListCached;
- static Boolean theWorldIsGood;
-
- static NMRec theErrorRec;
- static Str255 theErrorString;
-
- #define cErrorStrings 128
- enum {
- eNoSystem,
- eNoSharedMenus,
- eNoFinderMenuINIT,
- eCantInstallHandlers
- };
-
- static void maineventloop (void)
- {
- EventRecord ev;
-
- while (! flexitmainloop) {
- if (WaitNextEvent(everyEvent, &ev, 30, nil))
- if (theWorldIsGood && ev.what == kHighLevelEvent)
- AEProcessAppleEvent(&ev);
-
- if (theWorldIsGood)
- CheckSharedMenus(theFirstMenuID); /*See Step #2*/
- } /*while*/
- } /*maineventloop*/
-
-
- static void initmacintosh(void)
- {
- /*
- the magic stuff that every Macintosh application needs to do
- before doing anything else.
- */
-
- reg short i;
-
- SetApplLimit(CurStackBase - 32768);
-
- MaxApplZone();
- MoreMasters();
- InitGraf(&qd.thePort);
- // InitFonts();
- // FlushEvents(everyEvent, 0);
- // InitWindows();
- // InitMenus();
- // TEInit();
- // InitDialogs(nil);
- // InitCursor();
- } /*initmacintosh*/
-
-
- static pascal OSErr quitroutine(AppleEvent *event, AppleEvent *reply, long refcon)
- {
- if (! SharedScriptCancelled(event, reply))
- flexitmainloop = true;
-
- return (noErr);
- } /*quitroutine*/
-
-
- static pascal OSErr scriptcompletedcallback(event, reply, refcon)
- AppleEvent *event, *reply;
- long refcon;
- {
- AEDesc result;
-
- // REMINDSMZ: need to ensure ring is drawn
- if (AEGetParamDesc(event, 'errs', 'TEXT', &result) == noErr) { // something went wrong!
- texttostring(result.dataHandle, theErrorString);
-
- MemZero(&theErrorRec, sizeof(theErrorRec));
-
- theErrorRec.qType = nmType;
- theErrorRec.nmStr = (void*) &theErrorString;
- theErrorRec.nmResp = (void*) -1; // bloody vikings
- NMInstall(&theErrorRec);
-
- AEDisposeDesc(&result);
- }
-
- FMFinishedProcessing();
-
- return noErr;
- }
-
- static pascal OSErr GetFinderPaths(AppleEvent *event, AppleEvent *reply, long refcon)
- {
- return AEPutParamDesc(reply, '----', &thePathList);
- }
-
- static pascal OSErr HandleMenuHit(AppleEvent *event, AppleEvent *reply, long refcon)
- {
- short menuID, menuItem;
- DescType actualtype;
- Size actualsize;
-
- if (thePathListCached) { // destroy old
- AEDisposeDesc(&thePathList);
- thePathListCached = false;
- }
-
- if (AEGetParamPtr(event, 'mnid', typeShortInteger, &actualtype,
- (void*)&menuID, sizeof(short), &actualsize) == noErr)
- if (AEGetParamPtr(event, 'mnit', typeShortInteger, &actualtype,
- (void*)&menuItem, sizeof(short), &actualsize) == noErr)
- if (AEGetKeyDesc(event, 'flis', typeAEList, &thePathList) == noErr) {
- thePathListCached = true;
- FMRollBeachball();
- SharedMenuHit(menuID, menuItem);
- }
-
- return noErr;
- } /*HandleMenuHit*/
-
- static pascal OSErr HandleCancel(AppleEvent *event, AppleEvent *reply, long refcon)
- {
- if (MSglobals.flscriptrunning)
- CancelSharedScript();
-
- return noErr;
- } /*HandleCancel*/
-
- static pascal void NMDone(struct NMRect *aRec)
- {
- NMRemove(aRec);
- ExitToShell();
- }
-
- static void BadNews(short ixErr)
- {
- theWorldIsGood = false;
- GetIndString(theErrorString, cErrorStrings, ixErr);
- MemZero(&theErrorRec, sizeof(theErrorRec));
- theErrorRec.qType = nmType;
- theErrorRec.nmStr = (void*) &theErrorString;
- theErrorRec.nmResp = (void*) NMDone;
- if (NMInstall(&theErrorRec) != noErr)
- ExitToShell(); // oh, well
- }
-
- static void InitOtherFunctions()
- {
- theWorldIsGood = true; //always look on the bright side of life!
-
- // system 7 and applevents availiable?
- if (! (System7Running() || IAChaveappleevents())) {
- BadNews(eNoSystem);
- return;
- }
-
- // shared menus?
- if (! InitSharedMenus()) {
- BadNews(eNoSharedMenus);
- return;
- }
-
- MSglobals.scriptcompletedcallback = scriptcompletedcallback;
-
- // the findermenu hack?
-
- theFirstMenuID = FMInit();
-
- if (theFirstMenuID < 0) {
- BadNews(eNoFinderMenuINIT);
- return;
- }
-
- // other appleevent facilities?
- if (
- (AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, (ProcPtr) quitroutine, 0, false) != noErr)
- || (! IACinstallhandler(MSglobals.clientid, 'gsel', (ProcPtr) &GetFinderPaths))
- || (! IACinstallhandler(cGetFinderMenuProc, cFinderMenuHitEvent, (ProcPtr) &HandleMenuHit))
- || (! IACinstallhandler(cGetFinderMenuProc, cFinderCancelHitEvent, (ProcPtr) &HandleCancel))
- ) {
- BadNews(eCantInstallHandlers);
- return;
- }
- }
-
- void main (void)
- {
- initmacintosh();
-
- InitOtherFunctions();
-
- maineventloop();
-
- FMRemove();
- } /*main*/
-
-